part of '../repository.dart';

const _kAppStoreOneTimePurchasedItemTransactionIdKey = 'transaction_id';
const _kAppStoreOneTimePurchasedItemRevokedKey = 'revoked';

const _kAppStoreOneTimePurchasedItemTypeValue = 'one_time_purchased_item';

class _AppStoreOneTimePurchasedItemDto extends Equatable implements _AppStorePurchasedItemDto {
  const _AppStoreOneTimePurchasedItemDto._internal({
    required this.purchaseItemSku,
    required this.transactionId,
    required this.revoked,
  });

  @override
  final String purchaseItemSku;

  final String transactionId;
  final bool revoked;

  @override
  List<Object?> get props {
    return [
      purchaseItemSku,
      transactionId,
      revoked,
    ];
  }

  factory _AppStoreOneTimePurchasedItemDto.fromJson(Map<String, dynamic> json) {
    return _AppStoreOneTimePurchasedItemDto._internal(
      purchaseItemSku: json[_kAppStorePurchasedItemPurchaseItemSkuKey],
      transactionId: json[_kAppStoreOneTimePurchasedItemTransactionIdKey],
      revoked: json[_kAppStoreOneTimePurchasedItemRevokedKey],
    );
  }

  @override
  AppStoreOneTimePurchasedItem toEntity() {
    return AppStoreOneTimePurchasedItem(
      purchaseItemSku: purchaseItemSku,
      transactionId: transactionId,
      revoked: revoked,
    );
  }
}
